package com.runda.controller.delivery;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bbjob.dto.Result;
import com.bbjob.model.ExamineeScores;
import com.github.pagehelper.PageInfo;
import com.runda.query.QueryScores;
import com.runda.service.IExamineeScoresService;

@Api(tags = "examieescoresApi-delivery", description = "考生成绩管理(分发中心用绕过登录)")
@RestController
@RequestMapping(path = "delivery/examieescores", produces = "application/json;charset=utf-8")
public class DeliveryExamineeScoresController {
	
	@Resource
	private IExamineeScoresService scoreService;

	@ApiOperation(value="考试成绩列表", notes="考试成绩列表")
	@ApiImplicitParam(name="scores", value="考试成绩列表", required=true, dataType="QueryScores")
	@RequestMapping(value="list", method=RequestMethod.POST)
	public Result list(@RequestBody QueryScores scores) {
		
		List<ExamineeScores> data = scoreService.selectByParams(scores);
		PageInfo<ExamineeScores> pageInfo = new PageInfo<ExamineeScores>(data);
		
		return new Result(pageInfo);
	}
	
	@ApiOperation(value = "考试成绩录入", notes = "考试成绩录入（总）")
	@ApiImplicitParam(name = "scores", value = "考试成绩录入", required = true, dataType = "ExamineeScores")
	@RequestMapping(value = "save", method = RequestMethod.POST)
	public Result save(@RequestBody ExamineeScores scores) {

		if (scores.getUniquecode() != null && !"".equals(scores.getUniquecode())) {
			
			scoreService.saveByScores(scores);
			
			return new Result(scores);
		} else {
			return new Result(8106, "学校唯一编码为空，无法查询学校信息");
		}
	}
	
	@ApiOperation(value="修改考试成绩", notes="修改考试成绩")
	@ApiImplicitParams({
			@ApiImplicitParam(name="id", value="考试成绩信息id", required=true, dataType="Integer", paramType="path"),
			@ApiImplicitParam(name="scores", value="考试成绩", required=true, dataType="ExamineeScores")	
	})
	@RequestMapping(value="edit/{id}", method=RequestMethod.POST)
	public Result edit(@PathVariable("id")Integer id, @RequestBody ExamineeScores scores) {
		
		scores.setId(id);
		
		scores.setUpdateTime(new Date());
		
		this.scoreService.updateNotNull(scores);
		
		return new Result();
	}
	
	// listAll
	@ApiOperation(value="考试成绩列表(全)", notes="考试成绩列表--不分页")
	@ApiImplicitParam(name="scores", value="考试成绩列表", required=true, dataType="QueryScores")
	@RequestMapping(value="listAll", method=RequestMethod.POST)
	public Result listAll(@RequestBody QueryScores scores) {
		
		List<ExamineeScores> data = scoreService.selectAllByParams(scores);
		
		return new Result(data);
	}
}
	